#include <iostream>
#include "point.h"
#include "geometry.h"

class random_input
{
   int seed;
   static const int a = 1664525;
   static const int c = 1013904223;

   public:
   random_input(int seed): seed(seed)
   {
   }

   int get_int()
   {
      return (seed = seed * a + c) & 0x7fffffff;
   }

   double get_double()
   {
      const double low = -1000;
      const double high = 1000;
      const double scale = 1. / (1 << 30);
      return (low + (high - low) * scale * (get_int() & 0x3fffffff));
   }
};

int main()
{
	int n, type, seed;
   std::cin >> n >> type;

   random_input generator(0);
   
   if (type == 1)
   {
      std::cin >> seed;
      generator = random_input(seed);
   }

   int result = 0;
   int p = 1;
   for (int i = 0; i < n; i++, p *= 239)
   {
      point points[4];

      for (int j = 0; j < 4; j++)
         if (type == 0)
            std::cin >> points[j].x >> points[j].y;
         else
         {
            points[j].x = generator.get_double();
            points[j].y = generator.get_double();
         }
            

      if (intersection(points))
         result += p;
   }

	std::cout << result;
	
	return 0;
} 